package org.gwt.pluginframework.development;

import org.gwt.pluginframework.common.ComplexPlugin;
import org.gwt.pluginframework.common.IPluginManager;
import org.gwt.pluginframework.common.PluginManager;
import org.gwt.pluginframework.plugin.EventConsole;
import org.gwt.pluginframework.plugin.PerspectiveCenterExtension;
import org.gwt.pluginframework.plugin.PluginMonitor;
import org.gwt.pluginframework.plugin.SplashScreen;
import org.gwt.pluginframework.plugin.StatusBar;
import org.gwt.pluginframework.plugin.StatusBarEventInvoker;

import com.google.gwt.core.client.EntryPoint;

public class DevelopmentApplication implements EntryPoint {

	/**
	 * Override to add plugins to work with.
	 * 
	 * @param manager
	 */
	public void registerPlugins(IPluginManager manager) {
		// register your plugins
	}
	
	public DevelopmentDockExtension embedOnDockExtension() {
		// add to dock extension
		return new DevelopmentDockExtension();
	}
	
	public StatusBarEventInvoker[] registerCustomEvents() {
		return new StatusBarEventInvoker[] {};
	}
	
	public void onModuleLoad() {
		IPluginManager manager = new PluginManager();

		// splash screen - when created window is shown
		manager.registerPlugin(new SplashScreen());

		// logs any events and other messages (should be created as soon as
		// possibly
		EventConsole console = new EventConsole();
		manager.registerPlugin(console, false);

		// manager.registerPlugin(new BasicExceptionHandler());

		// we dont want to start plugin monitor at start
		manager.registerPlugin(new PluginMonitor(), false);

		ComplexPlugin perspective = new DevelopmentPerspective();
		manager.registerPlugin(perspective);

		StatusBar statusBar = new StatusBar();
		manager.registerPlugin(statusBar);
		statusBar.registerStatusBarEventInvokers(registerCustomEvents());
		
		// register custom development plugins
		registerPlugins(manager);
		
		// embed plugin on dock extension
		PerspectiveCenterExtension ext = embedOnDockExtension();

		perspective.registerExtension(DevelopmentPerspective.SOUTH_EXTENSION_POINT, statusBar);
		perspective.registerExtension(DevelopmentPerspective.CENTER_EXTENSION_POINT, ext);

		manager.run();
	}
}
